package com.elegantsoft.pakistannews;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.atiffarrukh.pakistannews.R;

public class MyCustommAdapter extends ArrayAdapter<String> {
	private final Context context;
	private final String[] values;

	public MyCustommAdapter(Context context, String[] values) {
		super(context, R.layout.row_cat, values);
		// TODO Auto-generated constructor stub
		this.values = values;
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.row_cat, parent, false);
		TextView textView = (TextView) rowView.findViewById(R.id.text1);
		ImageView imageView = (ImageView) rowView.findViewById(R.id.imageView1);
		textView.setText(values[position]);
		// Change the icon
		String s = values[position].toLowerCase().replace(" ", "");
		Resources res = context.getResources();
		String mDrawableName = s;
		int resID = res.getIdentifier(mDrawableName , "drawable", context.getPackageName());
		Drawable drawable = res.getDrawable(resID );
		imageView.setImageDrawable(drawable);
		

		return rowView;
	}
}
